<?php include '../public/header.php' ?>
<?php include '../public/header_index.php' ?>
<body class="laytp-container">
<div id="opt_nav">
</div>

<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">工程名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="enginname" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">款项类型</label>
                        <div class="layui-input-block">
                            <div id="houkoulei" class="xmselect_div">
                                <div class="xmselect_title">请选择</div>
                            </div>
                        </div>
                    </div>
<!--                    <div class="layui-col-md3">-->
<!--                        <label class="layui-form-label">数据来源：</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <select id="shulai" name="shulai" lay-filter="shulai">-->
<!--                                <option value="">请选择</option>-->
<!--                                <option value="1">工程回款</option>-->
<!--                                <option value="2">工程负责人预收款</option>-->
<!--                            </select>-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="layui-col-md3 search_hide none">-->
<!--                        <label class="layui-form-label">流程单号</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input type="text" name="sericnum" placeholder="请输入" class="layui-input" autocomplete="off">-->
<!--                        </div>-->
<!--                    </div>-->
                    <div class="layui-col-md3">
                        <label class="layui-form-label">到账日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="dt" placeholder="请输入" class="layui-input bdate_sea_range_ymd" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">收取性质：</label>
                        <div class="layui-input-block">
                            <select id="kouxing" name="kouxing" lay-filter="kouxing">
                                <option value="">请选择</option>
                                <option value="暂扣">暂扣</option>
                                <option value="实扣">实扣</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">资金状态：</label>
                        <div class="layui-input-block">
                            <select id="isdong" name="isdong" lay-filter="isdong">
                                <option value="">请选择</option>
                                <option value="0">冻结</option>
                                <option value="1">解冻</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">工程负责人</label>
                        <div class="layui-input-block">
                            <input type="text" name="gofuer" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">业务归属</label>
                        <div class="layui-input-block">
                            <div id="gui_unit" class="xmselect_div">
                                <div class="xmselect_title">请选择</div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">审核状态：</label>
                        <div class="layui-input-block">
                            <select id="status" name="status" lay-filter="status">
                                <option value="">请选择</option>
                                <option value="1">流程（审批通过）</option>
                                <option value="0">流程（审批中）</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <div class="layui-form-item search-div">
                            <div class="layui-form-item layui-inline">
                                <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                <button class="layui-btn layui-btn-primary" onclick="listTableReset()" id="TableSearchReset" type="reset" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
                                <div id="search_open" onclick="toggle_search()">
                                    <i class="layui-icon layui-icon-down"></i>展开
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-md12" id="table_list">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="test-dropdown-toolbar-barDemo">
    <div class="tab-list-authbut">
        <a href="javascript:;" class="bar_opt" onclick="auth_but_func_show('查看','{{d.LAY_TABLE_INDEX}}')">查看</a>
    </div>
</script>
<script type="text/html" id="toolbarDemo">
    <div class = "layui-btn-container">
    </div>
</script>
<script>
    var param_listtype = getQueryVariable('listtype') || 0;
    var param_enginid = getQueryVariable('enginid') || 0;
    var param_isdong = getQueryVariable('isdong') || '';

    var param_kouxing = decodeURI(getQueryVariable('kouxing') || '') || '';
    var param_gofuer = decodeURI(getQueryVariable('gofuer') || '') || '';
    if(param_gofuer){
        $("#gofuer").val(param_gofuer)
    }

    var param_sou_houkou = getQueryVariable('sou_houkou') || '';
    var param_status = getQueryVariable('status') || '';
    $("#status").val(param_status)


    var currButAuth, currTabData;
    layui.use(["laytp",'laypage','table','dropdown','form','soulTable'], function () {
        var laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;


        $('#TableSearchReset').click(function () {
            $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
            $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
            searchTableFunc(form, table)
        });


        setSouTableExport('直接收取明细');
        var mytable = table.render({
            elem: "#datalist",id: "datalist"
            ,url: facade.url(ask_hou_chi_kou_qifei_list),where: {enginid:param_enginid,isdong:param_isdong,
                gofuer:param_gofuer,status:param_status,sou_houkou:param_sou_houkou,kouxing:param_kouxing,listtype:param_listtype}, page: true, height: 'full-140'
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: TabInit.defaultToolbar,filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response,contextmenu:get_table_contextmenu(soulTable)
            ,text: TabInit.text,totalRow: true
            ,parseData: function (res) {
                currButAuth = res.data.butauth;
                tableButShow(currButAuth);

                xmselect_dan('houkoulei', res.data.houkoulei, res.data.is_houkoulei, function (res) {
                    setTimeout(function () {
                        searchTableFunc(form, table);
                    },100)
                })
                xmselect_dan('gui_unit', res.data.gui_unit, res.data.is_gui_unit, function (res) {
                    setTimeout(function () {
                        searchTableFunc(form, table);
                    },100)
                })

                render_from();
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.data.total,
                    "data": res.data.data.data
                };
            }
            , cols: [[
                {type: "checkbox", fixed: 'left'}
                ,{type:'numbers',title:'序号',totalRowText: '合计',fixed:'left'}
                ,{field: 'shulai', title: '数据来源'}
                ,{field: 'sericnum', title: '流程单号'}
                ,{field:'status',title:'审核状态',width:120,templet: function(d){
                        if(d.billid > 0){
                            if(d.status == 0){
                                if(d.type == 1){
                                    return '<div style="text-align: center"><span class="list_billid billstrlan" onclick="openPage(\'../hou_gonghui/show.php?id='+d.zhuid+'\');">审批中</span></div>'
                                }else{
                                    return '<div style="text-align: center"><span class="list_billid billstrlan" onclick="openPage(\'../hou_gongyu/show.php?id='+d.zhuid+'\');">审批中</span></div>'
                                }

                            }else if(d.status == 1){
                                if(d.type == 1){
                                    return '<div style="text-align: center"><span class="list_billid billstrlv" onclick="openPage(\'../hou_gonghui/show.php?id='+d.zhuid+'\');">审批通过</span></div>'
                                }else{
                                    return '<div style="text-align: center"><span class="list_billid billstrlv" onclick="openPage(\'../hou_gongyu/show.php?id='+d.zhuid+'\');">审批通过</span></div>'
                                }
                            }else{
                                return '';
                            }
                        }
                        return '';
                    }}
                ,{field: 'enginname', title: '费用所属工程名称'}
                ,{field: 'houkoulei_name', title: '款项类型'}
                ,{field: 'explain', title: '款项说明'}
                ,{field: 'qu_name', title: '资金渠道'}
                ,{field:'koufee',title:'当前渠道收取金额(元)',totalRow: true,templet: function(d){
                        return parseFormatNum(d.koufee);
                    }}
                ,{field: 'dt', title: '到账日期'}
                ,{field: 'kouxing', title: '收取性质'}
                ,{field: 'isdong_name', title: '资金状态'}
                ,{field: 'dongshuo', title: '解冻说明'}
                ,{field: 'dongdt', title: '解冻日期'}
                ,{field: 'donger', title: '解冻操作人'}
                ,{field: 'gofuer', title: '工程负责人'}
                ,{field: 'gui_unit_name', title: '业务归属'}
            ]]
            , done: function (res) {
                soulTable.render(this);

                currTabData = res.data;
                $.each(currTabData, function(index,item){
                    var chk = $('tr[data-index=' + item.LAY_TABLE_INDEX + '] .tab-list-authbut');
                    for (var key in currButAuth) {
                        if(currButAuth[key].pagetype === 0 || currButAuth[key].pagetype === 1){
                            if(currTabData[index].status != 1){
                                continue;
                            }
                            chk.append(' <a ' +
                                'href="javascript:;" ' +
                                'class="bar_opt layui-hide" ' +
                                'lay-event="search" ' +
                                'data-butname="'+currButAuth[key].butname+'" ' +
                                'data-title="'+currButAuth[key].title+'" ' +
                                'onclick="auth_but_func_'+currButAuth[key].butname+'(\''+currButAuth[key].title+'\', '+index+')"' +
                                '>'+currButAuth[key].title+'' +
                                '</a>');
                        }
                    }
                });
                show_tab_but(currTabData);
            }
        });


        listTableSearch(form, table);
    });


    function auth_but_func_dong(buttitle){
        var checkStatus = layui.table.checkStatus('datalist').data;
        var idArr = [];
        var shikou = false;
        for(var i=0;i<checkStatus.length;i++){
            if(checkStatus[i].kouxing == '实扣'){
                shikou = true;
            }
            idArr.push(checkStatus[i].id)
        }
        if(idArr.length < 1){
            facade.error(buttitle + "：请选择数据");return false;
        }
        if(shikou){
            facade.error(buttitle + "：仅可选择收取性质为暂扣的数据");return false;
        }
        openPageEdit('dong.php?close=1&ids='+idArr.join(','), '770px', '490px');
    }


    function get_table_check_idarr(datalist='datalist') {
        var checkStatus = layui.table.checkStatus(datalist).data;
        var ids = [];
        for(var i=0;i<checkStatus.length;i++){
            ids.push(checkStatus[i].id)
        }
        return ids;
    }



</script>
</body>
</html>
